package Opration;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("添加图书");
        System.out.println("请输入书名：");
        String name = scanner.nextLine();
        System.out.println("请输入作者：");
        String author = scanner.nextLine();
        System.out.println("请输入类型：");
        String type = scanner.nextLine();
        System.out.println("请输入价格：");
        int price = scanner.nextInt();
        Book book = new Book(name,author,type,price);
        for (int i = 0; i < bookList.getUseSized(); i++) {
           if(bookList.books[i].equals(book)){
               System.out.println("你的书架上已经有这本书了，不能再进行添加");
               return;
           }
        }
        bookList.setBooks(book, bookList.getUseSized());
        bookList.setUseSized(bookList.getUseSized() + 1);
    }
}
